<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		changeConfigAttr,
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey,
		hasEditor,
		getEditorTitle
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import moment from '@/static/js/moment.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				purchaseCacheKey:'mar-yx-biddingShow-purcase-cache',
				currencyDictIdCacheKey:'mar-yx-biddingShow-currencyDictId-cache',
				countryCacheKey:'mar-yx-biddingShow-country-cache',
				provinceCacheKey:'mar-yx-biddingShow-province-cache',
				cityCacheKey:'mar-yx-biddingShow-city-cache',
				districtCacheKey:'mar-yx-biddingShow-district-cache',
				coordinateUserCacheKey:'mar-yx-biddingShow-coordinateUser-cache',
				instCacheKey:'mar-yx-biddingShow-inst-cache',
				fileKey:"48",
				crossDistrictFiling: '',
				mapCode: {},
				salesClerkCacheKey:'mar-yx-biddingShow-salesClerk-cache',
				provideInstCacheKey:'mar-yx-biddingShow-provideInst-cache',
				productCategoryCacheKey:'mar-yx-biddingShow-productCategory-cache',
				biddingPlatformCacheKey:'mar-yx-biddingShow-biddingPlatform-cache',
				addressCacheKey:'mar-yx-biddingShow-address-cache'
			})
		},
		watch:{
			'formdata.purchaseAmount':function(newVal,oldVal){
				let _that = this
				if(_that.formdata.winRateNum){
					_that.$refs.autoform.formdata.expectedWinningAmount = (Number(newVal) * Number(_that.formdata.winRateNum) / 100).toFixed(2)
				}
			},
			'formdata.winRateNum':function(newVal,oldVal){
				let _that = this
				if(_that.formdata.purchaseAmount){
					_that.$refs.autoform.formdata.expectedWinningAmount = (Number(newVal)/100 * Number(_that.formdata.purchaseAmount)).toFixed(2)
				}
			},
			
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId','orgId'])
		},
		methods:{
			findRelatedDataList(id){
				let _that = this
				_that.om.request(
					'bidding/findRelatedDataList',
					{
						customerShowId:id,
						endDate:'',
						filterBiddingCode:_that.$refs.autoform.formdata.biddingCode
					}
				).then(res=>{
					_that.subEditorObj["title1"].workList =  res.value
				})
			},
			onSelectProjectPhase(item){
				let _that = this
				let formdata= _that.$refs.autoform.formdata
				formdata.winRateNum = Number(item.referNum)
				formdata.winRate = Number(item.referNum) / 100
			},
			verifyBiddingPlatform(){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				let title1 = _that.$refs.autoform.getEditorTitle("title2")
				let title2 = _that.$refs.autoform.getEditorTitle("title2","ifBiddingProjectId")
				if(formdata.ifBiddingProjectId && formdata.ifBiddingProjectId ==' 6433'){
					return true
				}else{
					_that.om.toast(title1+'的'+title2+'需优先完成编辑')
					return false
				}
			},
			onInputBudgetAmount(val){
				let _that = this
				_that.$refs.autoform.formdata.purchaseAmount = Number(val)
			},
			getPosComboboxByUser(id){
				let _that = this
				_that.om.request(
					'orgInstPosUserOfficial/getPosComboboxByUser',
					{
						userId:id
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor('title2',"postId","data",configSelectData(res,'id','posName'))
					_that.$refs.autoform.initSelectIndex("title2","postId")
				})
			},
			formSubmit(){
				let _that = this
				_that.formdata.updateBottomFileFlag= true
				if(Object.prototype.toString.call(_that.$refs.autoform.formdata.bottomFileList) == "[object String]"){
					_that.formdata.bottomFileListStr = _that.$refs.autoform.formdata.bottomFileList|| ''
				}else{
					_that.formdata.bottomFileListStr = JSON.stringify(_that.$refs.autoform.formdata.bottomFileList || []) || ''
				}
				delete _that.formdata.bottomFileUpload
				delete _that.formdata.bottomFileList
				_that.formdata.winRate = Number(_that.formdata.winRateNum) / 100
				if(_that.edit){
					_that.om.formSave("bidding/doUpdate",_that.formdata,_that)
				}else{
					_that.om.formSave("bidding/doAdd",_that.formdata,_that)
				}
			},
			changeProvinceParam(id){
				let _that = this
				_that.$refs.autoform.changeEditor("title2","provinceId",{
					"linkParam":{
						other:JSON.stringify({
							parentId: id,
							classifyCode:'35922',
						}),
						namefield:'dicname',
						initload:true,
						url:'compete/getRegions',
						cachename:_that.provinceCacheKey
					}
				})
			},
			changeCityParam(id){
				let _that = this
				_that.$refs.autoform.changeEditor("title2","cityId",{
					"linkParam":{
						other:JSON.stringify({
							parentId: id,
							classifyCode:'35923',
						}),
						namefield:'dicname',
						initload:true,
						url:'compete/getRegions',
						cachename:_that.cityCacheKey
					}
				})
			},
			verifyDistrict(){
				let _that = this
				if(!_that.$refs.autoform.formdata.countryId){
					let title = _that.$refs.autoform.getEditorTitle("title2","countryId")
					_that.om.toast("请先选择"+title)
					return false
				}else{
					_that.$refs.autoform.changeEditor("title2","locationId",{
						link:'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({
								parentId: _that.$refs.autoform.formdata.countryId,
								classifyCode:'35924'
							}),
							url:"compete/getRegions",
							initload:true,
							namefield:"dicname",
							cachename:_that.districtCacheKey
						}
					})
					return true
				}
			},
			onSelectIfBiddingProjectId(item){
				let _that = this
				if(item.id == _that.mapCode.DICT_YES_NO_CHOICE_STATE_YES_ID){
					_that.$refs.autoform.changeEditor("title2","countryId","type","linkbox")
					_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","biddingNum","type","textbox")
					_that.$refs.autoform.changeEditor("title2","biddingPlatformId","type","linkbox")
					_that.$refs.autoform.changeEditor("title2","tenderNumber","type","textbox")
					_that.$refs.autoform.changeEditor("title2","buyTime","type","newdatetimebox")
					_that.$refs.autoform.changeEditor("title2","endTime","type","newdatetimebox")
					_that.$refs.autoform.changeEditor("title2","estimatedProjectDate","type","newdatebox")
					_that.$refs.autoform.changeEditor("title2","biddingStartPlace","type","textarea")
					_that.$refs.autoform.changeEditor("title2","biddingStartDate","type","newdatebox")
				}else{
					_that.$refs.autoform.clear('title2', 'countryId');
					_that.$refs.autoform.clear('title2', 'locationId');
					_that.$refs.autoform.clear('title2', 'biddingNum');
					_that.$refs.autoform.clear('title2', 'biddingPlatformId');
					_that.$refs.autoform.clear('title2', 'website');
					_that.$refs.autoform.clear('title2', 'tenderNumber');
					_that.$refs.autoform.clear('title2', 'buyTime');
					_that.$refs.autoform.clear('title2', 'endTime');
					_that.$refs.autoform.clear('title2', 'estimatedProjectDate');
					_that.$refs.autoform.clear('title2', 'biddingStartPlace');
					_that.$refs.autoform.clear('title2', 'biddingStartDate');
					_that.$refs.autoform.changeEditor("title2","countryId","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","biddingNum","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","biddingPlatformId","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","tenderNumber","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","buyTime","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","endTime","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","estimatedProjectDate","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","biddingStartPlace","type","labelbox")
					_that.$refs.autoform.changeEditor("title2","biddingStartDate","type","labelbox")
				}
			},
			clearIfBiddingProjectId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'ifBiddingProjectId');
				_that.$refs.autoform.clear('title2', 'biddingNum');
				_that.$refs.autoform.clear('title2', 'biddingPlatformId');
				_that.$refs.autoform.clear('title2', 'website');
				_that.$refs.autoform.clear('title2', 'tenderNumber');
				_that.$refs.autoform.clear('title2', 'buyTime');
				_that.$refs.autoform.clear('title2', 'endTime');
				_that.$refs.autoform.clear('title2', 'estimatedProjectDate');
				_that.$refs.autoform.clear('title2', 'biddingStartPlace');
				_that.$refs.autoform.clear('title2', 'biddingStartDate');
				_that.$refs.autoform.changeEditor("title2","biddingNum","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","biddingPlatformId","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","tenderNumber","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","buyTime","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","endTime","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","estimatedProjectDate","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","biddingStartPlace","type","labelbox")
				_that.$refs.autoform.changeEditor("title2","biddingStartDate","type","labelbox")
			},
			onSelectCountryId(item){
				let _that = this
				if(item.id == 8){
					_that.$refs.autoform.changeEditor("title2","locationId","type","areabox")
				}else{
					_that.$refs.autoform.clear('title2', 'locationId');
					_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
				}
			},
			clearCountryId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'countryId');
				_that.$refs.autoform.clear('title2', 'locationId');
				_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
			},
			onSelectBiddingPlatform(item){
				let _that = this
				_that.$refs.autoform.formdata.website = item.website
			},
			onSelectCrossDistrictFiling(item){
				let _that = this
				_that.$refs.autoform.formdata.crossDistrictFiling = item.id
				_that.$refs.autoform.formdata.crossDistrictFilingStr = item.dicname
				_that.crossDistrictFiling = item.id
				if(_that.crossDistrictFiling != item.id){
					_that.$refs.autoform.clear('title2', 'purchaseNameId');
					_that.$refs.autoform.clear('title2', 'instId');
					_that.$refs.autoform.clear('title2', 'purchaseName');
					_that.$refs.autoform.clear('title2', 'customerCode');
					_that.$refs.autoform.clear('title2', 'customerShortName');
					_that.$refs.autoform.clear('title2', 'customerOwnerId');
				}
			},
			clearCrossDistrictFiling(){
				let _that = this
				_that.crossDistrictFiling = ''
				_that.$refs.autoform.clear('title2', 'crossDistrictFiling');
				_that.$refs.autoform.clear('title2', 'purchaseNameId');
				_that.$refs.autoform.clear('title2', 'instId');
				_that.$refs.autoform.clear('title2', 'purchaseName');
				_that.$refs.autoform.clear('title2', 'customerCode');
				_that.$refs.autoform.clear('title2', 'customerShortName');
				_that.$refs.autoform.clear('title2', 'customerOwnerId');
			},
			clearPurchaseNameId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'purchaseNameId');
				_that.$refs.autoform.clear('title2', 'instId');
				_that.$refs.autoform.clear('title2', 'purchaseName');
				_that.$refs.autoform.clear('title2', 'customerCode');
				_that.$refs.autoform.clear('title2', 'customerShortName');
				_that.$refs.autoform.clear('title2', 'customerOwnerId');
			},
			clearBiddingPlatformId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'biddingPlatformId');
				_that.$refs.autoform.clear('title2', 'website');
			},
			initLoad(options){
				let _that = this
				let fileId = options.fileId
				let ajaxArr = [
					urlUtil.zposUrl(options.code),
					{
						url:"bidding/getCodeLevel",
						param:{
							code:'39039'
						}
					},
					{
						url:"bidding/getCodeLevel",
						param:{
							code:'39042'
						}
					},
					{
						url:"bidding/getCodeLevel",
						param:{
							code:'39043'
						}
					},
					{
						url:"inventoryCategory/getExistingProductLineAssortment",
					},
					{
						url:"bidding/getBiddingPlatform",
						
					},
					{
						url:"dictZero/getListByCode",
						param:{
							code:'38400' 
						}
					},
					{
						url:"bidding/getCodeMap",
					},{
						url:'tsysdict/findChildrenByCodeNoIsdel',
						param:{
							code: '39127'
						}
					},{
						url:'dictSource/loadCombo',
						param:{
							sourceId:'289',
							categoryId:'8700'
						}
					},{
						url:'tsysdict/findChildrenByCodeNoIsdel',
						param:{
							code:'39127'
						}
					}]
					if(fileId){
						ajaxArr.push({
							url:"bidding/getValue",
							param:{
								fileId: fileId
							}
						})
					}
				formModelLoad(ajaxArr,function(res,mainData){
					_that.mapCode = res[7].value;
					changeEditor("title2","createDate",{
						defaultName:moment().format('YYYY-MM-DD'),
						defaultValue:moment().format('YYYY-MM-DD')
					},null,mainData)
					changeEditor("title2","purchaseWayId","data",configSelectData(res[9],'id','text'),mainData)
					changeEditor("title2","projectPhaseId","data",configSelectData(res[10],'id','dicname'),mainData)
					changeEditor("title2","salesClerkId", {
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other: JSON.stringify({
								firstUserId: _that.userId
							}),
							searchfield: 'q',
							namefield: 'userPosInstName',
							initload:true,
							url: 'temployee/getStaffCombogrid',
							cachename: _that.salesClerkCacheKey,
						},
					},null,mainData)
					changeEditor("title2","provideInstIdStr", {
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other: JSON.stringify({
								firstUserId: _that.userId
							}),
							searchfield: 'q',
							namefield: 'userPosInstName',
							initload:true,
							url: 'temployee/getStaffCombogrid',
							cachename: _that.salesClerkCacheKey,
						},
					},null,mainData)
					changeEditor("title2","projectPhaseId","data",configSelectData(res[8],'id','dicname'),mainData)
					changeEditor("topinfo","zposId","data",configSelectData(res[0],'id','posname'),mainData)
					changeEditor("title2","postId","data",configSelectData(res[0],'id','posname'),mainData)
					changeEditor("title2","crossDistrictFiling","data",configSelectData(res[6],'id','dicname'),mainData)
					changeEditor("title2","biddingTypeId","data",configSelectData(res[1],'id','dicname'),mainData)
					changeEditor("title2","businessTypeId","data",configSelectData(res[2],'id','dicname'),mainData)
					changeEditor("title2","businessFormId","data",configSelectData(res[3],'id','dicname'),mainData)
					changeEditor("title5","isParticipateId","data",configSelectData(res[6],'id','dicname'),mainData)
					changeEditor("title2","ifBiddingProjectId","data",configSelectData(res[6],'id','dicname'),mainData)
					changeEditor("title2","purchaseAmount",'suffixCol',2,mainData)
					changeEditor("title2","budgetAmount",'suffixCol',2,mainData)
					changeEditor("title2","locationId",'type','labelbox',mainData)
					changeEditor("title2","locationId", 'link', '../../public/pageSearch/pageSearch',mainData)
					changeEditor("title2","locationId",'linkParam', {
						other: JSON.stringify({
							classifyCode: '37056'
						}),
						searchfield: 'q',
						fullName:true,
						namefield: urlUtil.addressUrl().namefield,
						url: urlUtil.addressUrl().url,
						cachename: _that.addressCacheKey,
						placeholder: '请输入地址'
					},mainData)
					changeEditor("title2","purchaseNameId",{
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other:JSON.stringify({
								crossDistrict: _that.crossDistrictFiling,
								busCode: _that.busCode,
								userId: _that.userId
							}),
							namefield:'customerCode',
							notefield:'customerName',
							initload:true,
							searchfield:'q',
							pagination:true,
							cachename:_that.purchaseCacheKey,
							url:'bidding/getCustomerList',
							method:'get'
						}
					},null,mainData)
					changeEditor("title2","currencyDictId",{
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							namefield:'currencyCode',
							notefield:'currencyName',
							initload:true,
							searchfield:'q',
							pagination:true,
							cachename:_that.currencyDictIdCacheKey,
							url:'currencyDict/getCurrency',
							method:'get'
						}
					},null,mainData)
					changeEditor("title2","countryId",{
						link:'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({
							}),
							namefield:'dicname',
							initload:true,
							url:'regions/getCountryList',
							cachename:_that.countryCacheKey
						}
					},null,mainData)
					changeEditor("title2","provinceId",{
						link:'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({
								parentId: '',
								classifyCode:'35922',
							}),
							namefield:'dicname',
							initload:true,
							url:'compete/getRegions',
							cachename:_that.provinceCacheKey
						}
					},null,mainData)
					changeEditor("title2","cityId",{
						link:'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({
								parentId: '',
								classifyCode:'35923',
							}),
							namefield:'dicname',
							initload:true,
							url:'compete/getRegions',
							cachename:_that.cityCacheKey
						}
					},null,mainData)
					changeEditor("title2","provideInstIdStr",{
						"linkParam":{
							other:JSON.stringify({
							}),
							namefield:'text',
							initload:true,
							url:'tinstitution/getComboTree',
							cachename:_that.provideInstCacheKey
						}
					},null,mainData)
					changeEditor("title2","productCategoryId",{
						"linkParam":{
							other:JSON.stringify({
							}),
							namefield:'name',
							initload:true,
							url:'inventoryCategory/getExistingProductLineAssortment',
							cachename:_that.productCategoryCacheKey
						}
					},null,mainData)
					changeEditor("title2","biddingPlatformId",{
						link:'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({}),
							url:'bidding/getBiddingPlatform',
							namefield:'platformName',
							initload:true,
							cachename:_that.biddingPlatformCacheKey
						}
					},null,mainData)
					if(_that.subEditorObj["title1"]){
						let attr = {
							showAdd:false,
							showDel:false
						}
						let configData = _that.subConfigData["title1"]
						if(hasEditor("title1",'forecastPreparationName',configData)){
							let title = getEditorTitle("title1","forecastPreparationName",configData)
							attr.titleTemplate = title + ':<%= forecastPreparationName %>'
						}
						changeEditor("title1","relatedStr",attr,mainData)
					}
					
					changeEditor("title5","coordinateUserId",'isSearchUser',true,mainData)
					changeEditor("title5","coordinateUserId",{
						link:'../../public/searchUser/searchUser',
						"linkParam":{
							isSingle:true,
							cachename:_that.coordinateUserCacheKey
						}
					},null,mainData)
					
					let tempFileList = []
					let fileUrlList = []
					changeEditor('bottominfo','bottomFileUpload','fileUploadKey',"48",mainData)
					changeEditor("bottominfo","bottomFileUpload","tempFileList", tempFileList,mainData)
					changeEditor("bottominfo","bottomFileUpload","fileUrlList", fileUrlList,mainData)
					
					if(fileId){
						let fieldArr = getFormFields(mainData)
						fieldArr.push("id")
						for(let index in res[11].value){
							if(fieldArr.includes(index)){
								if(index == 'winRate'){
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'winRateNum',Number(res[11].value[index])*100)
									_that.$set(_that.formdata,'winRateNum',Number(res[11].value[index])*100)
								}
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,index,res[11].value[index])
								_that.$set(_that.formdata,index,res[11].value[index])
							}
						}
						if(_that.subEditorObj["title1"]){
							let dataList = _that._.cloneDeep(res[11].value.relatedList)
							_that.subEditorObj["title1"].workList = dataList
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"relatedStr",JSON.stringify(dataList))
							_that.$set(_that.formdata,"relatedStr",JSON.stringify(dataList))
						}
					
						if(_that.formdata.provideInstIdStr){
							let ids = _that.formdata.provideInstIdStr.split(",")
							let names = _that.formdata.provideInstNameStr.split(",")
							let provideInstList = []
							for(let index in ids){
								let obj = {
									id:ids[index],
									text:names[index]
								}
								provideInstList.push(obj)
							}	
							changeEditor("title2","provideInstIdStr",{
								initSelect:provideInstList
							},null,mainData)
						}
						if(_that.formdata.productCategoryId){
							let ids = _that.formdata.productCategoryId.split(",")
							let names = _that.formdata.productCategory.split(",")
							let productCategoryList = []
							for(let index in ids){
								let obj = {
									id:ids[index],
									text:names[index]
								}
								productCategoryList.push(obj)
							}	
							changeEditor("title2","productCategoryId",{
								initSelect:productCategoryList
							},null,mainData)
						}


						if(_that.formdata.bottomFileList){
							let tempFileList = []
							let fileUrlList = _that.formdata.bottomFileList.map(t=>{
								tempFileList.push(t.fileSaveName)
								return t.fileSaveName
							})
							changeEditor("bottominfo","bottomFileUpload","tempFileList", tempFileList,mainData)
							changeEditor("bottominfo","bottomFileUpload","fileUrlList", fileUrlList,mainData)
						}
						_that.$nextTick(function(){
							_that.$refs.autoform.initSelectIndex("topinfo","zposId")
							_that.$refs.autoform.initSelectIndex("title2","postId")
							_that.$refs.autoform.initSelectIndex("title2","crossDistrictFiling")
							_that.$refs.autoform.initSelectIndex("title2","biddingTypeId")
							_that.$refs.autoform.initSelectIndex("title2","businessTypeId")
							_that.$refs.autoform.initSelectIndex("title2","businessFormId")
							_that.$refs.autoform.initSelectIndex("title5","isParticipateId")
							_that.$refs.autoform.initSelectIndex("title2","ifBiddingProjectId")
							
							if(_that.$refs.autoform.formdata.ifBiddingProjectId == _that.mapCode.DICT_YES_NO_CHOICE_STATE_YES_ID){
								_that.$refs.autoform.changeEditor("title2","countryId","type","linkbox")
								_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","biddingNum","type","textbox")
								_that.$refs.autoform.changeEditor("title2","tenderNumber","type","textbox")
								_that.$refs.autoform.changeEditor("title2","buyTime","type","newdatetimebox")
								_that.$refs.autoform.changeEditor("title2","endTime","type","newdatetimebox")
								_that.$refs.autoform.changeEditor("title2","estimatedProjectDate","type","newdatebox")
								_that.$refs.autoform.changeEditor("title2","biddingStartPlace","type","textarea")
								_that.$refs.autoform.changeEditor("title2","biddingStartDate","type","newdatebox")
								_that.$refs.autoform.changeEditor("title2","biddingPlatformId","type","linkbox")	
							}else{
								_that.$refs.autoform.changeEditor("title2","countryId","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","biddingNum","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","tenderNumber","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","buyTime","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","endTime","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","estimatedProjectDate","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","biddingStartPlace","type","labelbox")
								_that.$refs.autoform.changeEditor("title2","biddingStartDate","type","labelbox")
							}
							
							if(_that.$refs.autoform.formdata.countryId){
								_that.changeProvinceParam(_that.$refs.autoform.formdata.countryId)
								if(_that.$refs.autoform.formdata.countryId == 8){
									_that.$refs.autoform.changeEditor("title2","locationId","type","areabox")
								}else{
									_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
								}
							}
							if(_that.$refs.autoform.formdata.provinceId){
								_that.changeCityParam(_that.$refs.autoform.formdata.provinceId)
							}
						})
					}
					_that.$nextTick(function(){
						if(!_that.$refs.autoform.formdata.zposId){
							_that.$refs.autoform.initSelectVal("topinfo","zposId")
							_that.$refs.autoform.formdata.postId = res[0][0].id
							_that.$refs.autoform.formdata.postName = res[0][0].posname
							_that.$refs.autoform.initSelectIndex("title2","postId")
							_that.$refs.autoform.formdata.salesInstId = res[0][0].instId
							_that.$refs.autoform.formdata.salesInstName = res[0][0].instName
						}
						if(!_that.$refs.autoform.formdata.salesClerkId){
							_that.$refs.autoform.formdata.salesClerkId = _that.userId
							_that.$refs.autoform.formdata.salesClerkName = _that.userName
						}
						_that.$refs.autoform.initSelectIndex("title2","projectPhaseId")
						_that.$refs.autoform.initSelectIndex("title2","purchaseWayId")
						if(!_that.$refs.autoform.formdata.currencyDictId){
							_that.om.request('currencyDict/getLocalCurrency', {
								
							},'post').then(res => {
								_that.$refs.autoform.formdata.currencyDictId = res.value.id
								_that.$refs.autoform.formdata.currencyDictName = res.value.codeNameUnit
								_that.$refs.autoform.formdata.currencyTypeUnit = res.value.currencyUnit
							});
						}
						if(!_that.$refs.autoform.formdata.biddingCode){
							_that.om.request('bidding/getMaxCode').then(res => {
								_that.$refs.autoform.formdata.biddingCode = res.value.biddingCode
								_that.$refs.autoform.formdata.biddingCodeDate = res.value.biddingCodeDate
								_that.$refs.autoform.formdata.biddingCodeNum = res.value.biddingCodeNum
							});
						}
						if(!_that.$refs.autoform.formdata.projectPhaseId){
							_that.$refs.autoform.formdata.projectPhaseId = _that.mapCode.DICT_BIDDING_PROJECT_1_ID
							_that.$refs.autoform.formdata.projectPhase = _that.mapCode.DICT_BIDDING_PROJECT_1_NAME
						}
					})
				},options)
			}
		},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.purchaseCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							if(Object.prototype.toString.call(d) == "[object Object]"){
								formdata.purchaseNameId = d.id
								formdata.customerEncode = d.customerCode
								formdata.instId = d.customerInstId
								formdata.inst = d.customerInstName
								formdata.purchaseName = d.customerName
								formdata.customerCode = d.customerCode
								formdata.customerShortName = d.customerShortName
								formdata.customerOwnerId = d.mainOwnerId
								formdata.customerOwner = d.mainOwnerName 
								if(_that.subEditorObj["title1"]){
									_that.findRelatedDataList(d.id)
								}
							}
							uni.removeStorage({
								key:_that.purchaseCacheKey
							})
						}
					} 
				})
				uni.getStorage({
					key:_that.provideInstCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.provideInstIdStr = d.map(e=>e.id).join(',')
							formdata.provideInstNameStr = d.map(e=>e.text).join(',')
							_that.$refs.autoform.changeEditor("title2","provideInstIdStr",{
								initSelect:d
							})
							uni.removeStorage({
								key:_that.provideInstCacheKey
							})
						}
					} 
				})
				uni.getStorage({
					key:_that.biddingPlatformCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.biddingPlatformId = d.id
							formdata.biddingPlatform = d.platformName
							formdata.website = d.website
							uni.removeStorage({
								key:_that.biddingPlatformCacheKey
							})
						}
					} 
				})
				uni.getStorage({
					key:_that.salesClerkCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.salesClerkId = d.id
							formdata.salesClerkName = d.username
							formdata.postId = d.salaryPosId
							formdata.postName = d.salaryPosName
							formdata.salesInstId = d.salaryPosInstId
							formdata.salesInstName = d.salaryPosInstName
							_that.getPosComboboxByUser(d.id)
							uni.removeStorage({
								key:_that.salesClerkCacheKey
							})
						}
					} 
				})
				uni.getStorage({
					key:_that.currencyDictIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.currencyDictId = d.id
							formdata.currencyDictName = d.codeNameUnit
							formdata.currencyTypeUnit = d.currencyUnit
							uni.removeStorage({
								key:_that.currencyDictIdCacheKey
							})
						}
					} 
				})
				uni.getStorage({
					key:_that.instCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.instId = d.id
							formdata.inst = d.instName
							uni.removeStorage({
								key:_that.instCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.countryCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.countryId = d.id
							formdata.country = d.dicname
							_that.$refs.autoform.clear("title2","provinceId")
							_that.$refs.autoform.clear("title2","cityId")
							_that.$refs.autoform.clear("title2","districtId")
							_that.changeProvinceParam(d.id)
							if(d.id == 8){
								_that.$refs.autoform.changeEditor("title2","locationId","type","areabox")
							}else{
								_that.$refs.autoform.clear('title2', 'locationId');
								_that.$refs.autoform.changeEditor("title2","locationId","type","labelbox")
							}
							
							uni.removeStorage({
								key:_that.countryCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.provinceCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.provinceId = d.id
							formdata.province = d.dicname
							_that.$refs.autoform.clear("title2","cityId")
							_that.$refs.autoform.clear("title2","districtId")
							_that.changeCityParam(d.id)
							uni.removeStorage({
								key:_that.provinceCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.cityCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.cityId = d.id
							formdata.city = d.dicname
							_that.$refs.autoform.clear("title2","districtId")
							uni.removeStorage({
								key:_that.cityCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.districtCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							_that.$refs.autoform.$refs.areapop.close()
							formdata.districtId = d.id
							formdata.district = d.dicname
							uni.removeStorage({
								key:_that.districtCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.productCategoryCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.productCategoryId = d.map(e=>e.id).join(',')
							formdata.productCategory = d.map(e=>e.name).join(',')
							_that.$refs.autoform.changeEditor('title2', 'productCategoryId', {
								initSelect: d
							})
							uni.removeStorage({
								key:_that.productCategoryCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.coordinateUserCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.coordinateUserId = d.id
							formdata.coordinateUser = d.username
							uni.removeStorage({
								key:_that.coordinateUserCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key: _that.addressCacheKey,
					success: function(res) {
						if (res.data) {
							let d = res.data;
							let formdata = _that.$refs.autoform.formdata;
							_that.$refs.autoform.$refs.areapop.close()
							formdata.locationId = d.id
							formdata.location = d.fullName
							uni.removeStorage({
								key: _that.addressCacheKey
							});
						}
					}
				});
			}
		}
	}
</script>
<style></style>                                                                                                                                                                                                                                                                                                                  
